var cookie_domain = '';
var cookie_pre    = 'alwu_';



function GID(Id){
	return document.getElementById(Id);
}

function isUndefineds(variable) {
	return typeof variable == 'undefined' ? true : false;
}

/**URL截取*/
function sub_url(url, lengths){
	if(url.length>lengths){
		var j = parseInt(lengths*0.5);
		url = url.substr(0,j)+"..."+url.substr(url.length-j,j);
	}
	return url;
}
/**转换成小写*/
function toLowerCaseStr(Str){
	return Str.toLowerCase();
}
/**转换成大写*/
function toUpperCaseStr(Str){
	return Str.toUpperCase();
}


function setSelectOption(objId, targetValue){
	var obj = document.getElementById(objId);
	if(obj){
	  var options = obj.options;
	  if(options){
		  var len = options.length;
		  for(var i=0;i<len;i++){
			  if(options[i].value == targetValue){
				  options[i].defaultSelected = true;
				  options[i].selected = true;
				  return true;
			  }
		  }
	  }
	}
	return false;
}

/**代码调试*/
function var_dump(obj) {
	if(typeof obj== "object") {
		var txt = '';
		for(key in obj){
			txt +=key + '=' + obj[key] + ',';
		}
		var retMessage = "Type: "+typeof(obj)+((obj.constructor) ? "\nConstructor: "+obj.constructor : "")+"\nValue: " + txt;
	} else {
		var retMessage = "Type  : "+typeof(obj)+"\nValue : "+obj+"\nLength: "+obj.length;
	}
	alert(retMessage);
	return retMessage;
}
/**验证邮箱用*/
function checkEmail(email){
	var str=email.match(/^\S+@\S+\.\S+$/);
		if(!str||!email) {
			return false;
		}
	return true;
}

/**  
 * 修正IE下document.getElementsByName无法获取DIV标签  
 * */ 

function getElementsByName(tag, name){   
	if(GetWebBrowsersName()!='Msie'){
		return  document.getElementsByName(name);
	}	
    returns = new Array();   
    var e = document.getElementsByTagName(tag);
    for (var i = 0; i < e.length; i++) {   
        if (e[i].getAttribute("name") == name) {   
            returns[returns.length] = e[i];   
        }   
    }   
	return returns;   
}

/**
 * JS 获取GET值
 **/
var $_GET=function(GetName){
	var paramStr=location.search;
	if(paramStr.length==0){
		return '';
	}
	if(paramStr.charAt(0)!='?'){
		return '';
	}
	paramStr=unescape(paramStr);
	paramStr=paramStr.substring(1);
	if(paramStr.length==0){
		return '';
	}
	var params=paramStr.split('&');
	for(var i=0;i<params.length;i++){
		var parts=params[i].split('=',2);
		if(parts[0]==GetName){
			if(parts.length<2||typeof(parts[1])=="undefined"||parts[1]=="undefined"||parts[1]=="null"){
				return '';
			}
			return parts[1];
		}
	}
	return '';
};

/**
 *  全选 checkbox 复选框
 **/
var is_checkbox = false;
function SelectAll(formName){
	is_checkbox=!is_checkbox;
	var kid = eval("document."+formName);
	for(var i=0;i<kid.elements.length;i++){
		if(kid.elements[i].type=="checkbox"){
			kid.elements[i].checked=is_checkbox;
		}
	}
}

/**
 * COOKIE 操作
 **/
var cookie = {
	getsec:function(str){ 
		try{
			var str1=str.substring(1,str.length)*1; 
			var str2=str.substring(0,1); 
		}catch(e){}
		
		if (str2=="s"){ 
			return str1*1000; 
		}else if (str2=="h"){ 
			return str1*60*60*1000; 
		}else if (str2=="d"){ 
			return str1*24*60*60*1000; 
		}else{
			return str;
		} 
	}, 
	
	set:function(name, value, time){  
		if(isUndefineds(time)) time='d30';
		var strsec = this.getsec(time); 
		
		var expires = new Date(); 
		expires.setTime(expires.getTime() + strsec); 
		
		/*document.cookie = cookie_pre+name + "="+ escape (value) + ";expires=" + expires.toGMTString()+";domain="+cookie_domain;*/  
	
		var argv = arguments;   
		var argc = arguments.length;   
		var path = (argc > 3) ? argv[3] : '/';   
		var domain = (argc > 4) ? argv[4] : cookie_domain;
		var secure = (argc > 5) ? argv[5] : false;   
		document.cookie = cookie_pre+name + "=" + escape (value) +   
		((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +   
		((path == null) ? "" : ("; path=" + path)) +   
		((domain == null) ? "" : ("; domain=" + domain)) +   
		((secure == true) ? "; secure" : "");
	}, 
	
	get:function(name){  
		var arg = cookie_pre+name + "=";   
		var alen = arg.length;   
		var clen = document.cookie.length;   
		var i = 0;   
		var j = 0;   
		while(i < clen){   
			j = i + alen;   
			if (document.cookie.substring(i, j) == arg)   
			return this.Val(j);   
			i = document.cookie.indexOf(" ", i) + 1;   
			if(i == 0)   
			break;   
		}   
		return null;   
	},  
	
	clear:function(name) {   
		if(this.get(name)){   
			var expdate = new Date();    
			expdate.setTime(expdate.getTime() - (86400 * 1000 * 1));    
			this.set(name, "", expdate);    
		}   
	},
	
	clearAll:function(){
		var strCookie=document.cookie;
		var arrCookie=strCookie.split("; ");
		for(var i=0;i <arrCookie.length;i++){
			var arr=arrCookie[i].split("=");
			if(arr.length>0){
				this.clear(arr[0]);
			} 
		}
	},
	Val:function(offset){   
		var endstr = document.cookie.indexOf(";", offset);
		if(endstr == -1){   
			endstr = document.cookie.length;   
		}   
		return unescape(document.cookie.substring(offset, endstr));   
	}
};


/**身份证号码验证*/
function checkidCard(Card,Msg){
	var v15 = /^\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d$/;
	var v18 = /^\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d[1-9x]$/;
	var idCard = GID(Card);
	if( idCard.value.length == 15 ){
		if( !idCard.value.match(v15) ){
			GID(Msg).innerHTML = '身份证号码格式错误';
			return false;
		}
	}else if( idCard.value.length == 18 ){
		if( !idCard.value.match(v18) ){
			GID(Msg).innerHTML = '身份证号码格式错误';
			return false;
		}
	}else{
		GID(Msg).innerHTML = '身份证号码格式错误';
		return false;
	}
	GID(Msg).innerHTML = '填写正确';
	return true;
}